package com.hdu.joinInMemory.repository;

import com.google.common.collect.Lists;
import com.hdu.joinInMemory.entity.DO.Order;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.stream.Collectors;


@Repository
public class OrderRepository {

    private static final List<Order> ORDERS = Lists.newArrayListWithCapacity(100);
    private static final Long USER_ID = 1L;

    static {
        for (long i = 0; i < 100; i++) {
            long j = i + 1;
            ORDERS.add(
                    Order.builder()
                            .id(j)
                            .userId(USER_ID)
                            .addressId(j)
                            .productId(j)
                            .build()
            );
        }
    }

    public List<Order> getOrderByUserId(Long userId) {
        return ORDERS.stream()
                .filter(order -> order.getUserId().equals(userId))
                .collect(Collectors.toList());
    }
}
